﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SapB1WebPOS.Model;

namespace SapB1WebPOS
{
    public partial class Popup : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session["LoginUserName"] == null
                || HttpContext.Current.Session["LoginPassword"] == null
                || HttpContext.Current.Session["UserPermission"] == null
                || HttpContext.Current.Session["IsSAPUser"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            string sPath = HttpContext.Current.Request.Url.AbsolutePath;
            string[] strarry = sPath.Split('/');
            int lengh = strarry.Length;
            string currentPage = strarry[lengh - 1];
            if (!(bool)HttpContext.Current.Session["IsSAPUser"])
            {
                if (HttpContext.Current.Session["UserPermission"] != null)
                {
                    bool isOK = false;

                    OnlineUser user = (OnlineUser)HttpContext.Current.Session["UserPermission"];

                    if (currentPage == "SalesQuotationList.aspx" && user.U_SalesQuotation == "Y")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "SalesOrderList.aspx" && user.U_SalesOrder == "Y")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "PurchaseRequestList.aspx" && user.U_PurchaseRequest == "Y")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "PurchaseOrderList.aspx" && user.U_PurchaseOrder == "Y")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "GoodReceiptPOList.aspx" && user.U_GRPO == "Y")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "ARInvoiceList.aspx" && user.U_WebPOS == "Y")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "ChangePassword.aspx")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "ItemMasterDataList.aspx")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "BusinessPartnersList.aspx")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "SAPPOSLineEdit.aspx")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "PaymentAmount.aspx")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "UserList.aspx")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "EmployeeList.aspx")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "POSBusinessPartnersList.aspx")
                    {
                        isOK = true;
                    }
                    else if (currentPage == "POSItemMasterDataList.aspx")
                    {
                        isOK = true;
                    }
                    if (!isOK)
                    {
                        Response.Redirect("AccessDenied.htm");
                    }
                }
                else
                {
                    Response.Redirect("AccessDenied.htm");
                }

            }
        }
    }
}